<template>
    <div>
        <van-nav-bar fixed="true" title="聊天消息"></van-nav-bar>
        <div style="height: 500px;margin-top: 46px;text-align: center">
            <van-pull-refresh style="height: 100%" v-model="isLoading" @refresh="onRefresh">
                <van-swipe-cell :key="item" v-for="item in loadUserLists">
                    <van-card @click="toChat(item.id)" :title="item.law_user_name" class="goods"
                              :thumb="item.law_user_image">
                    </van-card>
                    <template #right>
                        <van-button square text="删除" @click="deleteChat(item.id)" type="danger" class="delete-button"/>
                    </template>
                </van-swipe-cell>
            </van-pull-refresh>
        </div>
    </div>
</template>


<script>
    import Toast from "vant/lib/toast";

    export default {
        name: "userChat",
        data() {
            return {
                count: 0,
                isLoading: true,
                UserLists: '',
                loadUserLists: [],
            };
        },
        methods: {
            onRefresh() {
                setTimeout(() => {
                    this.getChatList();
                    Toast('刷新成功');
                    this.isLoading = false;
                    this.count++;
                }, 1000);
            },
            toChat(id) {
                this.$router.push({path: 'chat1', query: {id: id}})
            },
            // 删除最近聊天
            deleteChat(id) {
                let user = JSON.parse(localStorage.getItem('token') || '{}');
                this.toUser = user
                this.$axios.post('/status/deleteChatList', {
                    // "fromUser":this.$route.query.id,
                    "fromUser"         : id,
                    "toUser": this.toUser.id
                }),
                    this.$toast.success('删除成功！')
                this.getChatList()
            },
            // 最近聊天消息列表
            getChatList: function () {
                let user = JSON.parse(localStorage.getItem('token') || '{}');
                this.toUser = user
                this.$axios.post('/status/getChatList1?id=' + this.toUser.id,
                    {}, res => {
                        this.loadUserLists = res.data.data
                        console.log(this.loadUserLists);
                    })
            }
        },
        created() {
            this.getChatList();
        }
    }
</script>


<style scoped>
    .goods-card {
        margin: 0;
    }

    .delete-button {
        height: 100%;
    }
</style>
